/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.yunhoo.salary.util;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.yunhoo.govProcure.bean.BuildAssetBean;
import com.yunhoo.sys.db.util.IbatisTemplate;
import com.yunhoo.sys.login.LoginBean;
import com.yunhoo.sys.util.common.LoginParam;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * 工资查询工具类
 *
 * @author Administrator
 */
public class SalaToolKit {

    private String dbServer = "";
    private String dbName = "";
    //private String ltdb = "";
    private String uid = "";
    private String pwd = "";

    public SalaToolKit(String db_type) {
        try {
//            ServletContext scontext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
//            Properties props = new Properties();
//            InputStream in = new FileInputStream(scontext.getRealPath(filePath));
//            props.load(in);
            Map<String, String> dbConfigMap = initMap(db_type);
            dbServer = dbConfigMap.get("dbServer");
            dbName = dbConfigMap.get("dbName");
            uid = dbConfigMap.get("uid");
            pwd = dbConfigMap.get("pwd");
            //ltdb = dbConfigMap.get("ltdb");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private Map<String, String> initMap(String db_type) {
        SqlMapClient client = IbatisTemplate.getSqlMapClient();
        Map<String, String> map = null;
        try {
            client.startTransaction();
            
            Map paramMap = new HashMap();
            paramMap.put("orgCode",LoginParam.getOrg().getCode());
            paramMap.put("db_type",db_type);
            map = client.queryForMap("sysConfig.queryMapConfig", paramMap, "key", "value");
            
            client.commitTransaction();
        } catch (SQLException ex) {
            try {
                client.endTransaction();
            } catch (SQLException ex1) {
                Logger.getLogger(LoginBean.class.getName()).log(Level.SEVERE, null, ex1);
            }
            Logger.getLogger(BuildAssetBean.class.getName()).log(Level.SEVERE, null, ex);
        }
        return map;
    }

    public String getDbName() {
        return dbName;
    }

    public void setDbName(String dbName) {
        this.dbName = dbName;
    }

    public String getDbServer() {
        return dbServer;
    }

    public void setDbServer(String dbServer) {
        this.dbServer = dbServer;
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    public String getUid() {
        return uid;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }

//    public String getLtdb() {
//        return ltdb;
//    }
//
//    public void setLtdb(String ltdb) {
//        this.ltdb = ltdb;
//    }
    public static void main(String[] args) {
    }
}
